import java.util.ArrayList;
import java.util.Random;

public class Player {

	Difficulty difficulty;
	double difficultyMultiplier;
	
	public String playerName;
	public Pet activePet;
	public Pet passivePet;
	public int money;
	public Random seed;
	public int seedN;
	public int nodeIndex = 0;
	public Inventory inventory;
	public boolean aniPlaying = false;
	public ArrayList<Integer> activeQuests = new ArrayList<Integer>();
	public ArrayList<Integer> finishedQuests = new ArrayList<Integer>();
	public ArrayList<Integer> defeatedTrainers = new ArrayList<Integer>();
	public SpellBook spellBook=new SpellBook();
	
	public boolean isAI;
	
	public Player(String name, int startingMoney, int seed, Pet startingPet, Pet passivePet, Difficulty difficulty, int nodeIndex) {
		playerName = name;
		money = startingMoney;
		this.seedN = seed;
		this.seed = new Random(seed);
		inventory = new Inventory();
		activePet = startingPet;
		if(passivePet!=null)
			this.passivePet=passivePet;
		this.nodeIndex = nodeIndex;
		addToSpellBook();
		
		if (difficulty == null) {
			isAI = true;
		} else {
			isAI = false;
			this.difficulty = difficulty;
			switch (difficulty) {
			case Sandbox: difficultyMultiplier = 0.3; break;
			case Easy: difficultyMultiplier = 0.7; break;
			case Normal: difficultyMultiplier = 1; break;
			case Difficult: difficultyMultiplier = 1.2; break;
			case Hardcore: difficultyMultiplier = 1.4; break;
			case Roguelike: difficultyMultiplier = 1.4; break;
			}
		}
			
	}
	
	public void addToSpellBook(){
		for(int i=0; i<activePet.attacks.size();i++){
			spellBook.addItem(activePet.attacks.get(i));
		}
		if(passivePet!=null){
			for(int i=0; i<passivePet.attacks.size();i++){
				spellBook.addItem(passivePet.attacks.get(i));
			}
		}
		
	}
	
	public Player copy() {
		Player duplicate;
		if (this.passivePet == null) {
			duplicate = new Player(playerName, money, seedN, activePet.copy(), null, difficulty, nodeIndex);
		}else{
			duplicate = new Player(playerName, money, seedN, activePet.copy(), passivePet.copy(), difficulty, nodeIndex);
		}
		duplicate.inventory = inventory.copy();
		return duplicate;
	}
	
	public void swapPet(){

		Pet temp;
		temp=activePet;
		activePet=passivePet;
		passivePet=temp;
		passivePet.energy = 0;
	}
	
	public void finishQuest(int qi) {
		activeQuests.remove((Integer) qi);
		finishedQuests.add(qi);
	}
}
